package com.cskaoyan._06oop3._01polymorphic._03demo;

/**
 * @author Macro_Ray
 * @since 2024/3/13 17:52
 */
/*
定义Person类//饲养员属性:姓名，年龄
行为:
keepPet(Dog dog,String something)方法功能:喂养宠物狗，something表示喂养的东西
行为:
keepPet(Cat cat,String something)方法功能:喂养宠物猫，something表示喂养的东西

keepPet(Dog dog,String something)方法打印内容如下
年龄为30岁的老王养了一只黑颜色的2岁的狗
2岁的黑颜色的狗两只前腿死死的抱住骨头猛吃
keepPet(Cat cat,String something)方法打印内容如下:
年龄为25岁的老李养了一只灰颜色的3岁的猫
3岁的灰颜色的猫眯着眼睛侧着头吃鱼

思考：
    1.Dog和cat都是Animal的子类，以上案例中针对不同的动物，定义了不同的keepPet方法，过于繁琐，
    能否简化，并体会简化后的好处?
    2.Dog和cat虽然都是Anima1的子类，但是都有其特有方法，能否想办法在keepPet中调用特有方法?*
*/
public class Demo {
    public static void main(String[] args) {
        /*Person laow = new Person("老王", 30);
        Dog dog = new Dog(2, "黑");
        laow.keepPet(dog, "骨头");
        System.out.println("------------------------------");
        Person laol = new Person("老李", 25);
        Animal cat = new Cat(3, "灰");
        laol.keepPet((Cat) cat, "鱼");*/

        Person p = new Person("老王",30);
        Dog d= new Dog(2,"黑");
        Cat c = new Cat(3,"灰");
        p.keepPet(d,"骨头");
        p.keepPet(c,"鱼");
    }
}

class Animal {
    private int age;
    private String color;

    public Animal() {
    }

    public Animal(int age, String color) {
        this.age = age;
        this.color = color;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public void eat(String something) {
        System.out.println("动物在吃" + something);
    }

}

class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    /*public void keepPet(Dog dog, String something) {
        System.out.println("年龄为" + age + "岁的" + name + "养了一只" + dog.getAge() + "岁的" + dog.getColor() + "颜色的狗");
        dog.eat(something);
    }

    public void keepPet(Cat cat, String something) {
        System.out.println("年龄为" + age + "岁的" + name + "养了一只" + cat.getAge() + "岁的" + cat.getColor() + "颜色的猫");
        cat.eat(something);
    }*/

    // 我想要一个方法能接收所有的动物
    // 方法的形参可以写父类Animal
    public void keepPet(Animal animal,String something){
        System.out.println("年龄为" + age + "岁的" + name + "养了一只" + animal.getAge() + "岁的" + animal.getColor() + "颜色的动物");
        animal.eat(something);
    }
}

class Dog extends Animal {
    public Dog() {
    }

    public Dog(int age, String color) {
        super(age, color);
    }

    @Override
    public void eat(String something) {
        System.out.println(getAge() + "岁的" + getColor() + "颜色的狗狗两只前腿死死的抱住" + something + "猛吃");
    }

    public void lookHome() {
        System.out.println("狗狗会看家");
    }
}

class Cat extends Animal {
    public Cat() {
    }

    public Cat(int age, String color) {
        super(age, color);
    }

    @Override
    public void eat(String something) {
        System.out.println(getAge() + "岁的" + getColor() + "颜色的猫猫眯着眼睛侧着头吃" + something);
    }

    public void catchMouse() {
        System.out.println("猫猫抓老鼠");
    }
}